<?php
include 'connect.php';
$username = $_POST['username'];
$password = $_POST['password'];


// 检查用户名是否已存在
$checkSql = "SELECT * FROM member WHERE username='$username'";
$checkResult = mysqli_query($link, $checkSql);

if (mysqli_num_rows($checkResult) > 0) {
    echo "用户名已存在，请选择其他用户名。";
}else{
    $sql = "INSERT INTO member  VALUES (null ,'$username', '$password')";
    $result = mysqli_query($link, $sql);
    if ($result) {
        echo "注册成功，请登录。";
        header("Location:login.html");
    } else {
        echo "注册失败：" . mysqli_error($link);
    }
}